// pages/mineV1/mineV1.js
import Dialog from '../../vant-weapp/dialog/dialog';
import fw from "../../core/framework.js"
const _app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isLogin: false,
    showLogin: false,
    merchantName: '',
    version:fw.config.version,
    isEasyUI:fw.user.isEasyUI(),
    pageBottom:_app.BOTTOM_DISTANCE||0,
    msgCount:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  setTabBar(data,selected){
    if (typeof this.getTabBar === 'function' && this.getTabBar()) { 
      this.getTabBar().setData({
        selected: selected || 1,
        list:data || fw.config.tabBar.basic
      })
    }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var self = this;
    var userData = fw.user.get();
    fw.clearTerminalChoose();
    this.setData({
      isLogin: !!userData.token,
      merchantName: userData.merchantName
    });
    if (this.data.isLogin) {
      fw.setUntreatedAlarmEvent((count)=>{
        self.setData({
          msgCount:count
        })
      });
    }
  },
  onClose() {
    this.setData({
      showLogin: false
    })
  },
  goLogin(e) {
    fw.url.goLogin(e);
  },
  goPage(event) {
    var self = this;
    var pagename = event.currentTarget.dataset.pagename;
    var _go = function (pageName) {
      console.log(pageName)
      fw.url.go(pageName);
    };
    if (!this.data.isLogin) {
      this.setData({
        showLogin: true
      })
    } else {
      _go(pagename);
    }
  },
  goUserInfo(){
    if (!this.data.isLogin) {
      this.setData({
        showLogin: true
      })
    } else {
      fw.url.go('user_info');
    }
    
  }
})